package com.itheima.service.impl;

import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckItemDao;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemServcice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;

@Service
public class CheckItemServiceimpl implements CheckItemServcice {

    @Autowired
    CheckItemDao checkItemDao;

    @Override
    public void addCheckItem(CheckItem checkItem) {
        // 实现添加检查项的逻辑

        CheckItem checkItem1 = checkItemDao.findByCode(checkItem.getCode());
        if(checkItem1 != null){
            throw new RuntimeException("检查项编码重复");
        }
        checkItemDao.addCheckItem(checkItem);
        // 例如，保存到数据库或其他存储
    }

    @Override
    public void deleteCheckItem(Integer id) {

        checkItemDao.deleteCheckGroupAndCheckItem(id);
        checkItemDao.deleteCheckItem(id);

    }

    @Override
    public List<Integer> findCheckItemIdsByCheckGroupId(Integer id) {

        List<Integer> ids = checkItemDao.findCheckItemIdsByCheckGroupId(id);
        return ids;

    }

    @Override
    public void editCheckItem(CheckItem checkItem) {
        checkItemDao.editCheckItem(checkItem);
    }

    @Override
    public List<CheckItem> findPage(QueryPageBean queryPageBean) {

        int start = (queryPageBean.getCurrentPage() - 1) * queryPageBean.getPageSize();
        int end = start + queryPageBean.getPageSize();
        return checkItemDao.findPage(start, end, queryPageBean.getQueryString());

    }

    @Override
    public Long findCount() {

        return checkItemDao.findCount() != null ? checkItemDao.findCount() : 0L;
    }

    @Override
    public List<CheckItem> findAll() {
        return checkItemDao.findAll() ;
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkItemDao.findById(id);
    }
}
